package com.qm.datax.configuration;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;

import static cn.hutool.core.lang.Console.log;

/**
 * @Author：wangshali
 * @CreateTime：2024-10-31
 * @Description：
 * @Source:
 * @Sink:
 * @Version：v1.0
 */

public class Configuration {
    public static String MYSQL_USER;
    public static String MYSQL_PASSWORD;
    public static String MYSQL_HOST;
    public static String MYSQL_PORT;
    public static String MYSQL_DATABASE;
    public static String MYSQL_URL;
    public static String MYSQL_TABLES;

    public static String CK_USER;
    public static String CK_PASSWORD;
    public static String CK_HOST;
    public static String CK_PORT;
    public static String CK_DATABASE;
    public static String CK_URL;
    public static String CK_TABLES;

    public static String IS_SEPERATED_TABLES;
    public static String HDFS_URI;


    public static String IMPORT_OUT_DIR;
    public static String EXPORT_OUT_DIR;


    public static String MIGRATION_TYPE;
    public static String SYNCHRONIZE_TYPE;
    public static String ARGS;


    static {
        Path path = Paths.get("D:\\code\\datax-config-generator\\src\\main\\resources\\configuration.properties");
        Properties configuration = new Properties();

        try {
            configuration.load(Files.newBufferedReader(path));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        MIGRATION_TYPE=configuration.getProperty("migration_type");
        SYNCHRONIZE_TYPE = configuration.getProperty("synchronize_type");
        IS_SEPERATED_TABLES = configuration.getProperty("is.seperated.tables");
        HDFS_URI = configuration.getProperty("hdfs.uri");
        IMPORT_OUT_DIR = configuration.getProperty("import_out_dir");
        EXPORT_OUT_DIR = configuration.getProperty("export_out_dir");


        ARGS = configuration.getProperty("mysql.active");
        log("当前同步的数据库是：" + ARGS + "...");

        MYSQL_HOST = configuration.getProperty(ARGS + ".host");
        MYSQL_PORT = configuration.getProperty(ARGS + ".port");
        MYSQL_DATABASE = configuration.getProperty(ARGS + ".database");
        MYSQL_TABLES = configuration.getProperty(ARGS + ".tables");
        MYSQL_USER = configuration.getProperty(ARGS + ".username");
        MYSQL_PASSWORD = configuration.getProperty(ARGS + ".password");
        MYSQL_URL = "jdbc:mysql://" + MYSQL_HOST + ":" + MYSQL_PORT + "/" + MYSQL_DATABASE + "?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=utf-8";


        CK_HOST = configuration.getProperty("ck.host");
        CK_PORT = configuration.getProperty("ck.port");
        CK_DATABASE = configuration.getProperty("ck.database");
        CK_TABLES = configuration.getProperty("ck.tables");
        CK_USER = configuration.getProperty("ck.username");
        CK_PASSWORD = configuration.getProperty("ck.password");
        CK_URL = "jdbc:clickhouse://" + CK_HOST + ":" + CK_PORT + "/" + CK_DATABASE;


    }

    public static void main(String[] args) {
        System.out.println(CK_DATABASE);
        System.out.println(CK_HOST);
    }

}
